define(['jquery','repairMsg','text!../template/repair.html','css!../css/repair','common'],function($,repairMsg,tplRepair){
	let _news = {};
	let currentPage = 1;
	let currentType = '';
	var tpls = {
		'tplRepair' :_.template(tplRepair)
	};

	_news.show = function(){
		currentPage = 1;
		$('#contant').html(tpls.tplRepair());

		$('.repairType').click(function(event) {
			$('.repairType').removeClass('selected');
			$(this).addClass('selected');
			currentType = $(this).attr('id');
			currentPage = 1;
			let str = $('#repairInput').val();
			let maintainGrade = $('#repairStatus').val();
			setTable(0,5,currentType,str,maintainGrade);
		});

		$('#repairSearch').click(function(event) {
			currentPage = 1;
			let str = $('#repairInput').val();
			let maintainGrade = $('#repairStatus').val();
			setTable(0,5,currentType,str,maintainGrade)
		});

		$('.repairType').eq(0).click();
	}

	function setTable(from,count,type,parm,grade){
		let status = type=='repIng'?1:2;

		layui.use('table', function(){
			var table = layui.table;
			let parms = {};
			parms.from = from;
			parms.count = count;
			parms.status = status;
			parms.searchParam = parm?parm:'';
			parms.maintainGrade = grade?grade:'';
			table.render({
				elem: '#gridRepairTable',
				url:'/xjrest/main/list_main',
				where: parms,
				even: '',
				cols: [[
					{ field: 'pointName', title: '建设地点', width: "11%", align: 'center',templet: function(d){
	                	return `<span title='${d.pointName}'>${truncate(d.pointName,9)}</span>`;
	                }},
	                { field: 'manufacturer', title: '器材厂家', width: "11%", align: 'center',templet: function(d){
	                	return `<span title='${d.manufacturer}'>${truncate(d.manufacturer,9)}</span>`;
	                }},
	                { field: 'dealName', title: '维修人', width: "12%", align: 'center' },
	                { field: 'maintainGrade', title: '维修等级', width: "11%",align: 'center',templet: function(d){
	                	return d.maintainGrade==1?'一般维修':'紧急维修'
	                }},
	                { field: 'beginTime', title: '维修开始时间', width: "11%", align: 'center',hide:type!='repIng'?true:false,templet: function(d){
	                	return d.beginTime.substring(5)
	                }},
	                { field: 'endTime', title: '维修截止时间', width: "11%", align: 'center',hide:type!='repIng'?true:false,templet: function(d){
	                	return d.endTime.substring(5)
	                }},
	                { field: 'userName', title: '上报人', width: "11%", align: 'center',hide:type=='repIng'?true:false},
	                { field: 'finishTime', title: '维修时间', width: "11%", align: 'center',hide:type=='repIng'?true:false,templet: function(d){
	                	return d.finishTime.substring(5)
	                }},
	                { field: 'equipmentType', title: '器材类型', width: "11%", align: 'center',templet: function(d){
	                	return d.equipmentType==1?'体彩':'自建'
	                }},
	                { field: 'buildTime', title: '建设时间', width: "11%", align: 'center' },
	                { field: 'phone', title: '联系电话', width: "11%", align: 'center' }
				]],
				parseData: function(res){
					return {
				        "code": 0,
				        "msg": res.ret.success,
				        "count": res.ret.total,
				        "data": res.ret.value
				    };
				},
				done: function(res, curr, count){
					table.on('rowDouble(repairTable)', function(obj){
					    Ajax("/xjrest/main/main_detail?maintainId="+obj.data.maintainId,function(data){
					    	repairMsg.show(data.ret);
					    });
					});

					let totals = count;
		            if (totals == 0) {
		                $("#noRecordMessage").show();
		            } else {
		                $("#noRecordMessage").hide();
		            }
		            if (0 == totals % 5) {
		                totalPage = parseInt(totals / 5);
		                if (totalPage == 0){
		                     totalPage = 1;
		                }
		            } else {
		                totalPage = parseInt(totals / 5) + 1;
		            }
		            $('#pagination').paginations({
		                currentPage: currentPage,
		                totalPage: totalPage,
		                callback: function(current) {
		                    currentPage = current;
		                    current = (current - 1) * 5;
		                    setTable(current,5,type,parms);
		                }
		            });
				}
			});
		});
	}

	return _news;
	
})